package com.changgou.seckill.cntroller;

import com.changgou.entity.Result;
import com.changgou.entity.StatusCode;
import com.changgou.seckill.config.TokenDecode;
import com.changgou.seckill.service.SeckillOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: HuangFu
 * @Date: 2020/2/23 10:51
 * @Description:
 */
@RestController
@RequestMapping("/seckillorder")
public class SecKillOrderController {

    @Autowired
    private SeckillOrderService seckillOrderService;
    @Autowired
    private TokenDecode tokenDecode;

    @PostMapping("/add")
    public Result add(@RequestParam("time") String time,@RequestParam("id") Long id){
        //获取用户名
        String username = tokenDecode.getUserInfo().get("username");

        boolean result = seckillOrderService.add(username,id,time);
        if(result){
            return new Result(true, StatusCode.OK, "抢单成功");
        }else {
            return new Result(false, StatusCode.OK, "抢单失败");
        }
    }

}
